using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VCUZUST
    {
        public DataRow Convert2CUZUST(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryCUZUST(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["CUZMANDANT"] = " ".PadRight(2 ); 
         dwReturn["CUZZUSTKRS"] = " ".PadRight(2 ); 
         dwReturn["CUZZUSTLFD"] = " ".PadRight(4 ); 
         dwReturn["CUZZUSTPOS"] = " ".PadRight(2 ); 
         dwReturn["CUZBEZ"] = " ".PadRight(20 ); 
         dwReturn["CUZTYP"] = " ".PadRight(1 ); 
         dwReturn["CUZLO"] = " ".PadRight(2 ); 
         dwReturn["CUZLB"] = " ".PadRight(2 ); 
         dwReturn["CUZLP"] = " ".PadRight(8 ); 
         dwReturn["CUZAUFBKZ"] = " ".PadRight(1 ); 
         dwReturn["CUZLOS"] = " ".PadRight(2 ); 
         dwReturn["CUZLBS"] = " ".PadRight(2 ); 
         dwReturn["CUZLPS"] = " ".PadRight(8 ); 
         dwReturn["CUZAUFBKZS"] = " ".PadRight(1 ); 
         dwReturn["CUZDATS"] = " ".PadRight(0 ); 
         dwReturn["CUZRVOR"] = " ".PadRight(2 ); 
         dwReturn["CUZSTPLGRP"] = " ".PadRight(2 ); 
         dwReturn["CUZSS"] = " ".PadRight(2 ); 
         dwReturn["CUZREINPL"] = " ".PadRight(0 ); 
         dwReturn["CUZANZCUT"] = " ".PadRight(0 ); 
         dwReturn["CUZNEUB"] = " ".PadRight(8 ); 
         dwReturn["CUZNEUD"] = " ".PadRight(0 ); 
         dwReturn["CUZAENB"] = " ".PadRight(8 ); 
         dwReturn["CUZAEND"] = " ".PadRight(0 ); 
         dwReturn["CUZAENZL"] = " ".PadRight(0 ); 
         dwReturn["CUZFILLER"] = " ".PadRight(25 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapCUZUST(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveCUZUST(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryCUZUST(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapCUZUST(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertCUZUST(dwLocal, ITXDBVERSION);
            }
            UpdateCUZUST(dwLocal);
        }
        public void InsertCUZUST(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO CUZUST(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryCUZUST(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM CUZUST WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM CUZUST  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "CUZUST";
            Return = Result;
            return Return;
        }
        public void DeleteCUZUST(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM CUZUST   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateCUZUST(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE CUZUST SET "
                    +"CUZMANDANT= :CUZMANDANT,"
                    +"CUZZUSTKRS= :CUZZUSTKRS,"
                    +"CUZZUSTLFD= :CUZZUSTLFD,"
                    +"CUZZUSTPOS= :CUZZUSTPOS,"
                    +"CUZBEZ= :CUZBEZ,"
                    +"CUZTYP= :CUZTYP,"
                    +"CUZLO= :CUZLO,"
                    +"CUZLB= :CUZLB,"
                    +"CUZLP= :CUZLP,"
                    +"CUZAUFBKZ= :CUZAUFBKZ,"
                    +"CUZLOS= :CUZLOS,"
                    +"CUZLBS= :CUZLBS,"
                    +"CUZLPS= :CUZLPS,"
                    +"CUZAUFBKZS= :CUZAUFBKZS,"
                    +"CUZDATS= :CUZDATS,"
                    +"CUZRVOR= :CUZRVOR,"
                    +"CUZSTPLGRP= :CUZSTPLGRP,"
                    +"CUZSS= :CUZSS,"
                    +"CUZREINPL= :CUZREINPL,"
                    +"CUZANZCUT= :CUZANZCUT,"
                    +"CUZNEUB= :CUZNEUB,"
                    +"CUZNEUD= :CUZNEUD,"
                    +"CUZAENB= :CUZAENB,"
                    +"CUZAEND= :CUZAEND,"
                    +"CUZAENZL= :CUZAENZL,"
                    +"CUZFILLER= :CUZFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("CUZMANDANT", OracleType.NVarChar).Value = dwData["CUZMANDANT"].ToString(); 
          or1.Parameters.Add("CUZZUSTKRS", OracleType.NVarChar).Value = dwData["CUZZUSTKRS"].ToString(); 
          or1.Parameters.Add("CUZZUSTLFD", OracleType.NVarChar).Value = dwData["CUZZUSTLFD"].ToString(); 
          or1.Parameters.Add("CUZZUSTPOS", OracleType.NVarChar).Value = dwData["CUZZUSTPOS"].ToString(); 
          or1.Parameters.Add("CUZBEZ", OracleType.NVarChar).Value = dwData["CUZBEZ"].ToString(); 
          or1.Parameters.Add("CUZTYP", OracleType.NVarChar).Value = dwData["CUZTYP"].ToString(); 
          or1.Parameters.Add("CUZLO", OracleType.NVarChar).Value = dwData["CUZLO"].ToString(); 
          or1.Parameters.Add("CUZLB", OracleType.NVarChar).Value = dwData["CUZLB"].ToString(); 
          or1.Parameters.Add("CUZLP", OracleType.NVarChar).Value = dwData["CUZLP"].ToString(); 
          or1.Parameters.Add("CUZAUFBKZ", OracleType.NVarChar).Value = dwData["CUZAUFBKZ"].ToString(); 
          or1.Parameters.Add("CUZLOS", OracleType.NVarChar).Value = dwData["CUZLOS"].ToString(); 
          or1.Parameters.Add("CUZLBS", OracleType.NVarChar).Value = dwData["CUZLBS"].ToString(); 
          or1.Parameters.Add("CUZLPS", OracleType.NVarChar).Value = dwData["CUZLPS"].ToString(); 
          or1.Parameters.Add("CUZAUFBKZS", OracleType.NVarChar).Value = dwData["CUZAUFBKZS"].ToString(); 
          or1.Parameters.Add("CUZDATS", OracleType.NVarChar).Value = dwData["CUZDATS"].ToString(); 
          or1.Parameters.Add("CUZRVOR", OracleType.NVarChar).Value = dwData["CUZRVOR"].ToString(); 
          or1.Parameters.Add("CUZSTPLGRP", OracleType.NVarChar).Value = dwData["CUZSTPLGRP"].ToString(); 
          or1.Parameters.Add("CUZSS", OracleType.NVarChar).Value = dwData["CUZSS"].ToString(); 
          or1.Parameters.Add("CUZREINPL", OracleType.NVarChar).Value = dwData["CUZREINPL"].ToString(); 
          or1.Parameters.Add("CUZANZCUT", OracleType.NVarChar).Value = dwData["CUZANZCUT"].ToString(); 
          or1.Parameters.Add("CUZNEUB", OracleType.NVarChar).Value = dwData["CUZNEUB"].ToString(); 
          or1.Parameters.Add("CUZNEUD", OracleType.NVarChar).Value = dwData["CUZNEUD"].ToString(); 
          or1.Parameters.Add("CUZAENB", OracleType.NVarChar).Value = dwData["CUZAENB"].ToString(); 
          or1.Parameters.Add("CUZAEND", OracleType.NVarChar).Value = dwData["CUZAEND"].ToString(); 
          or1.Parameters.Add("CUZAENZL", OracleType.NVarChar).Value = dwData["CUZAENZL"].ToString(); 
          or1.Parameters.Add("CUZFILLER", OracleType.NVarChar).Value = dwData["CUZFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
